layui.define([], function (exports) {

    var MOD_NAME = 'econsole',
        $ = layui.jquery

        var econsole = function(opt) {
            this.option = opt;
        };


    function appendElemToConsoleContent(option){
        var dom = `
            <div class="console-box">
                <div class="console-drag"></div>
                <div class="console-content" id="console-content">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">运行日志</li>
                            <li>调试信息</li></li>
                            <div class="fr iconBox">
                                <i class="layui-icon layui-icon-down"></i>
                                <i class="layui-icon layui-icon-up" style="display: none;"></i>
                            </div>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">站位</div>
                            <div class="layui-tab-item">内容2</div>
                        </div>
                    </div>
                </div>
            </div>
            
            
        `
        $(option.elem).append(dom);
    }


    econsole.prototype.render = function (opt) {

            var option = {
                elem: opt.elem,
                collapsed: false ||  opt.collapsed
            }

            appendElemToConsoleContent(option)

            if(option.collapsed){
                this.shrink(option.elem)
            }
            $(option.elem + ' .layui-icon-down').on('click', ()=>{
                // 点击向下箭头
                this.shrink(option.elem)
            })

            $(option.elem + ' .layui-icon-up').on('click', ()=>{
                // 点击向上箭头
                this.open(option.elem)
            })
            
            

            return new econsole(option);
        }


        // 收缩面板
        econsole.prototype.shrink = function(elem){
            $(elem + ' .layui-tab-content').hide();
            $('.console-drag').hide();
            $(elem + ' .layui-icon-down').hide();
            $(elem + ' .layui-icon-up').show()
            $('.console-box').height('19')
           
        }
        // 展开面板
        econsole.prototype.open = function(elem){
                $(elem + ' .layui-tab-content').show();
                $(elem + ' .layui-icon-up').hide();
                $('.console-drag').show();
                $(elem + ' .layui-icon-down').show()
                $('.console-box').height('calc(30%)')
        }

    exports(MOD_NAME, new econsole());
});
